package com.tituaem.gui;

import com.tituaem.operacionesftp.SubirArchivo;
import com.tituaem.utilityclass.Class_Action;
import com.tituaem.utilityclass.Class_KeyStroke;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import UpperEssential.UpperEssentialLookAndFeel;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class Principal extends javax.swing.JFrame {
    
    Log l=new Log(this, true);
    Class_KeyStroke ks=new Class_KeyStroke();
    Class_KeyStroke ks1=new Class_KeyStroke();
    Class_Action action=new Class_Action();
    Class_Action action1=new Class_Action();

    public Principal() {
        initComponents();
        setLocationRelativeTo(null);
        setDefaultCloseOperation(0);
        tesisBtn.setVisible(false);
        subirArchivoBtn.setVisible(false);
        /*Log in*/
        ks.setEscapeKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); 
        action.setEscapeAction(new AbstractAction(){
            @Override
            public void actionPerformed(ActionEvent e) {
                if(l.isAcc()==false){
                    l.setVisible(true);
                    if(l.isAcc()==true){
                        tesisBtn.setVisible(true);
                        subirArchivoBtn.setVisible(true);
                    }
                }
            }
        });
        /*Log out*/
        ks1.setEscapeKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); 
        action1.setEscapeAction(new AbstractAction(){
            @Override
            public void actionPerformed(ActionEvent e) {
                if(l.isAcc()==true){
                    JOptionPane.showMessageDialog(null, "Hasta Luego...", "", JOptionPane.INFORMATION_MESSAGE);
                    l.setAcc(false);
                        tesisBtn.setVisible(false);
                        subirArchivoBtn.setVisible(false);
                }
            }
        });
        getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks.getEscapeKeyStroke(), "ABRIR");
        getRootPane().getActionMap().put("ABRIR", action.getEscapeAction());
        getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks1.getEscapeKeyStroke(), "CERRAR");
        getRootPane().getActionMap().put("CERRAR", action1.getEscapeAction());
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        salirBtn = new javax.swing.JButton();
        acercadeBtn = new javax.swing.JButton();
        tesisBtn = new javax.swing.JButton();
        subirArchivoBtn = new javax.swing.JButton();
        configuracionBtn = new javax.swing.JButton();
        reportesBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        salirBtn.setText("Salir");
        salirBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirBtnActionPerformed(evt);
            }
        });

        acercadeBtn.setText("Acerca de...");

        tesisBtn.setText("Tesis");
        tesisBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tesisBtnActionPerformed(evt);
            }
        });

        subirArchivoBtn.setText("Subir Archivo");
        subirArchivoBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subirArchivoBtnActionPerformed(evt);
            }
        });

        configuracionBtn.setText("Configuracion");
        configuracionBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configuracionBtnActionPerformed(evt);
            }
        });

        reportesBtn.setText("Reportes");
        reportesBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reportesBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(acercadeBtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(salirBtn)
                .addGap(21, 21, 21))
            .addGroup(layout.createSequentialGroup()
                .addGap(197, 197, 197)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tesisBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(reportesBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(configuracionBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(subirArchivoBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(208, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(tesisBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(subirArchivoBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(reportesBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(configuracionBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(salirBtn)
                    .addComponent(acercadeBtn))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void salirBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirBtnActionPerformed
        System.exit(0);
    }//GEN-LAST:event_salirBtnActionPerformed

    private void tesisBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tesisBtnActionPerformed

        Tesis t=new Tesis(this, true);
        t.setVisible(true);
    }//GEN-LAST:event_tesisBtnActionPerformed

    private void subirArchivoBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subirArchivoBtnActionPerformed
        try {
            /**
             * Esta accion sube el archivo a el servidor ftp
             */
            
            SubirArchivo sa=new SubirArchivo();
            sa.subirArchivoPresentacionesFuturas();
            
        } catch (IOException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
            
        
    }//GEN-LAST:event_subirArchivoBtnActionPerformed

    private void configuracionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configuracionBtnActionPerformed
        
    }//GEN-LAST:event_configuracionBtnActionPerformed

    private void reportesBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportesBtnActionPerformed

        PresentacionesGUI p=new PresentacionesGUI(this, true);
        p.setVisible(true);
    }//GEN-LAST:event_reportesBtnActionPerformed

    public static void main(String args[]) {
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        try{
            UIManager.setLookAndFeel(new UpperEssentialLookAndFeel());
        }
        catch(Exception ex){
            
        }
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton acercadeBtn;
    private javax.swing.JButton configuracionBtn;
    private javax.swing.JButton reportesBtn;
    private javax.swing.JButton salirBtn;
    private javax.swing.JButton subirArchivoBtn;
    private javax.swing.JButton tesisBtn;
    // End of variables declaration//GEN-END:variables
}
